package com.zyw.weibo.ui.support;

import com.zyw.weibo.ui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.emagsoftware.ui.adapterview.DataHolder;
import cn.emagsoftware.ui.adapterview.ViewHolder;

public class EditProfileDataHolder extends DataHolder {
	
	public static final int TYPE_NICKNAME = 0;
	public static final int TYPE_MYDESCRIPTION = 1;
	
	private String value = null;
	
	public EditProfileDataHolder(int type,String value){
		super(type, 0);
		this.value = value;
	}
	
	public void setValue(String value){
		this.value = value;
	}
	
	public String getValue(){
		return value;
	}
	
	@Override
	public View onCreateView(Context arg0, int arg1, Object arg2) {
		// TODO Auto-generated method stub
		RelativeLayout wrap = (RelativeLayout)LayoutInflater.from(arg0).inflate(R.layout.editprofile_list_item, null);
		wrap.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT,AbsListView.LayoutParams.WRAP_CONTENT));
		TextView key = (TextView)wrap.findViewById(R.id.tvEditProfileKey);
		TextView value = (TextView)wrap.findViewById(R.id.tvEditProfileValue);
		ViewHolder viewHolder = new ViewHolder(key,value);
		wrap.setTag(viewHolder);
		onUpdateView(arg0,arg1,wrap,arg2,false);
		return wrap;
	}

	@Override
	public void onUpdateView(Context arg0, int arg1, View arg2, Object arg3, boolean arg4) {
		// TODO Auto-generated method stub
		if(arg1 == 0) arg2.setBackgroundResource(R.drawable.main_more_list_top_bg);
		else arg2.setBackgroundResource(R.drawable.main_more_list_bottom_bg);
		View[] views = ((ViewHolder)arg2.getTag()).getParams();
		TextView key = (TextView)views[0];
		TextView value = (TextView)views[1];
		Integer type = (Integer)arg3;
		if(type == TYPE_NICKNAME) key.setText(R.string.editprofile_field_nickname);
		else key.setText(R.string.editprofile_field_sex_mydescription);
		value.setText(this.value);
	}
	
}
